package com.b511.swpu.cementbackend.util;

import org.springframework.stereotype.Component;

import java.util.Arrays;

@Component
public class CodeUtil {
    public String next(String code) {
        char[] chars = code.toCharArray();
        boolean next = false;
        for (int i = code.length() - 1; i >= 0; i--) {
            if (chars[i] == 'Z' || (next && chars[i] == 'Y')) {
                chars[i] = '0';
                next = true;
            } else {
                if (chars[i] == '9' || (next && chars[i] == '8')) {
                    chars[i] = 'A';
                } else {
                    chars[i] = (char) (chars[i] + 1);
                }
                next = false;
            }
            if (!next) {
                break;
            }
        }
        return String.valueOf(chars);
    }

    public String initCode(int codeLength) {
        char[] result = new char[codeLength];
        Arrays.fill(result, '0');
        return String.valueOf(result);
    }
}
